package tool

import "github.com/mojocn/base64Captcha"


type CaptchaResult struct {
	Id          string `json:"id"`
	Base64Blob  string `json:"base_64_blob"`
	VerifyValue string `json:"verify_value"`
}

var GlobalCaptchaService *base64Captcha.Captcha

// InitCaptchaService 初始化
func InitCaptchaService() {
	// 配置选项
	driver := &base64Captcha.DriverString{
		Height:          35,
		Width:           120,
		NoiseCount:      0,
		ShowLineOptions: 0,
		Length:          4,
		Source:          base64Captcha.TxtSimpleCharaters,
		//BgColor:         &color.RGBA{
		//	R: 3,
		//	G: 102,
		//	B: 214,
		//	A: 254,
		//},
	}

	GlobalCaptchaService = base64Captcha.NewCaptcha(
		driver,
		&GlobalRedisStore,
	)
}

// GenerateCaptcha 生成验证码
func GenerateCaptcha() (string, string, error) {
	return GlobalCaptchaService.Generate()
}

func VerifyCaptcha(id string, answer string) (bool) {
	return GlobalCaptchaService.Store.Verify(id, answer, false)
}
